home *** CD-ROM | disk | FTP | other *** search
- /*
- * menu.c - menu handling for Interval.
- *
- */
-
- #include <quickdraw.h>
- #include <window.h>
- #include <menu.h>
- #include <desk.h>
- #include <control.h>
- #define ALLDIM 255 /* should be in control.h, but isn't */
- #include <dialog.h>
- #include <resource.h>
-
- #include "ival.h"
-
- #define APPLEMENU 1 /* Menu ID for Apple menu */
- #define FILEMENU 2 /* ...File menu */
- #define EDITMENU 3 /* ...Edit menu */
- #define CONFMENU 4 /* ...Configuration menu */
- #define LASTMENU 4 /* Number of menus */
-
- /* items in the Apple menu */
- #define DLGABOUT 256 /* About... */
-
- /* Items in the File menu */
- #define IQUIT 1 /* quit the program */
-
- /* items in the Edit menu */
- #define UNDOEDIT 1 /* Undo */
- /*----2----*/
- #define CUTEDIT 3 /* Cut */
- #define COPYEDIT 4 /* Copy */
- #define PASTEEDIT 5 /* Paste */
- #define CLEAREDIT 6 /* Clear */
-
- /* items in the Configuration menu */
- #define EX_TYPE 1 /* who does what */
- #define IV_TYPE 2 /* interval type selection */
-
- MenuHandle mymenus[LASTMENU + 1]; /* menus[1..LASTMENU] */
-
- #define DLGEX_TYPE 257 /* ResID of the "who does what" dialog */
- #define NOTEPROG 5 /* "program gives notation" item */
- #define NAMEPROG 6 /* "program gives name" */
- #define SNDPROG 7 /* "program gives sound" */
- #define NOTESTUD 8 /* "student gives notation" */
- #define NAMESTUD 9 /* "student gives name" */
- #define SNDSTUD 10 /* "student gives sound" (unimplemented)*/
-
- #define DLGMISC 258 /* Resid of the "Misc Configuration" dlg */
- /* the following 3 items must have sequential numbers */
- #define MI_HARM 3 /* "Harmonic intervals" item */
- #define MI_MEL 4 /* "Melodic intervals" */
- #define MI_MIX 5 /* "mixture" */
-
- #define MI_ACCOK 6 /* "allow accidentals" */
-
- /*
- * setupmenus() - Initialize the menus and desk accessories (drivers).
- */
-
- setupmenus()
- {
- int i;
-
- for (i = 1; i <= LASTMENU; i++) {
- mymenus[i] = GetMenu(i); /* our menu ID's start at 1 */
- }
-
- AddResMenu(mymenus[APPLEMENU], 'DRVR');
- for (i = 1; i <= LASTMENU; i++) {
- /* insert menus; 0 => put at end */
- InsertMenu(mymenus[i], 0);
- }
- DrawMenuBar();
- }
-
- /*
- * docommand() - handle a command given through a menu selection.
- *
- * If the command is Quit, we return true, else false.
- * Since the menu was highlighted by MenuSelect, we must finish
- * by unhighlighting it to indicate we're done.
- */
-
- int
- docommand(mresult)
- long mresult; /* the command to execute (a menu item) */
- {
- int refnum;
- int themenu; /* menu the mouse chose */
- int theitem; /* item in that menu */
- WindowPtr actwindow; /* the active (front) window */
- char name[255];
- int returns; /* value to be returned */
- GrafPtr saveport;
-
- returns = 0;
- themenu = HiWord(mresult);
- theitem = LoWord(mresult);
- actwindow = FrontWindow();
- switch (themenu) {
- case 0: /* no selection -- do nothing */
- break;
-
- case APPLEMENU:
- if (theitem == 1) { /* Tell about the program */
- saydialog(DLGABOUT);
- } else { /* Run a desk accessory */
- GetPort(&saveport);
- GetItem(mymenus[APPLEMENU], theitem, name);
- refnum = OpenDeskAcc(name);
- SetPort(saveport);
- }
- break;
-
- case FILEMENU:
- switch (theitem) {
- case IQUIT: /* quit */
- returns = 1;
- break;
- }
- break;
-
- case EDITMENU:
- switch (theitem) {
- case UNDOEDIT:
- case CUTEDIT:
- case COPYEDIT:
- case PASTEEDIT:
- case CLEAREDIT:
- if (actwindow == windoc) { /* do nothing */
- } else { /* a DA's window */
- SystemEdit(theitem - 1);
- }
- break;
- }
- break;
-
- case CONFMENU:
- switch (theitem) {
- case EX_TYPE: dlgtasks(); break;
- case IV_TYPE: dlgmisc(); break;
- }
- break;
- }
- HiliteMenu(0); /* we're done -- turn off the highlighting */
- return(returns);
- }
-
- /*
- * markmenus() - take care of checking and dimming all items in all menus.
- * This routine should be the only one that fiddles with menu item
- * checking and dimming.
- */
-
- markmenus(whichwindow)
- WindowPtr whichwindow; /* the active window */
- {
- MenuHandle themenu;
- char txt[64]; /* (pascal) menu item text */
-
- /* Apple menu is O.K. */
- /* File menu is O.K. */
-
- /*
- * Edit menu: dim it if our window is active.
- * Otherwise, light it.
- */
-
- themenu = mymenus[EDITMENU];
- if (whichwindow == windoc) {
- DisableItem(themenu, UNDOEDIT);
- DisableItem(themenu, CUTEDIT);
- DisableItem(themenu, COPYEDIT);
- DisableItem(themenu, PASTEEDIT);
- DisableItem(themenu, CLEAREDIT);
- } else {
- EnableItem(themenu, UNDOEDIT);
- EnableItem(themenu, CUTEDIT);
- EnableItem(themenu, COPYEDIT);
- EnableItem(themenu, PASTEEDIT);
- EnableItem(themenu, CLEAREDIT);
- }
-
- /*
- * Configuration menu: dim it if our window is not active.
- * Otherwise, light it.
- */
-
- themenu = mymenus[CONFMENU];
- if (whichwindow != windoc) {
- DisableItem(themenu, EX_TYPE);
- DisableItem(themenu, IV_TYPE);
- } else {
- EnableItem(themenu, EX_TYPE);
- EnableItem(themenu, IV_TYPE);
- }
- }
-
- /*
- * dlgtasks() - do the "What to do" dialog.
- */
-
- dlgtasks()
- {
- DialogPtr dlg; /* our dialog */
- short itemhit; /* item # of the selected item */
- struct tasks studcopy; /* local version of studtasks */
- struct tasks progcopy; /* local version of progtasks */
-
- /*
- * copy the state we're going to fiddle with
- * so we can leave the original unchanged, if necessary.
- */
-
- studcopy.notate = studtasks.notate;
- studcopy.name = studtasks.name;
- studcopy.sound = studtasks.sound;
-
- progcopy.notate = progtasks.notate;
- progcopy.name = progtasks.name;
- progcopy.sound = progtasks.sound;
-
- /*
- * Create and maintain the dialog,
- * Always updating the state of the buttons before allowing user input.
- */
-
- dlg = GetNewDialog(DLGEX_TYPE, (char *) 0, (long) -1);
- do {
- flagbutton(dlg, progcopy.notate, NOTEPROG, NOTESTUD);
- flagbutton(dlg, progcopy.name, NAMEPROG, NAMESTUD);
- flagbutton(dlg, progcopy.sound, SNDPROG, SNDSTUD);
-
- ModalDialog((ProcPtr) 0, &itemhit);
- switch (itemhit) {
- case NOTEPROG:
- progcopy.notate = !progcopy.notate;
- studcopy.notate = !progcopy.notate;
- break;
- case NAMEPROG:
- progcopy.name = !progcopy.name;
- studcopy.name = !progcopy.name;
- break;
- case SNDPROG:
- /*
- * Since the machine can't hear,
- * the following lines aren't here.
- progcopy.sound = !progcopy.sound;
- studcopy.sound = !progcopy.sound;
- */
- break;
- case NOTESTUD:
- studcopy.notate = !studcopy.notate;
- progcopy.notate = !studcopy.notate;
- break;
- case NAMESTUD:
- studcopy.name = !studcopy.name;
- progcopy.name = !studcopy.name;
- break;
- case SNDSTUD:
- /*
- * Since the machine can't hear,
- * the following lines aren't here.
- studcopy.sound = !studcopy.sound;
- progcopy.sound = !studcopy.sound;
- */
- break;
- }
- } while (itemhit != OK && itemhit != Cancel);
- DisposDialog(dlg);
-
- if (itemhit == Cancel) return;
-
- /*
- * Put the specified changes into effect.
- */
-
- studtasks.notate = studcopy.notate;
- studtasks.name = studcopy.name;
- studtasks.sound = studcopy.sound;
-
- progtasks.notate = progcopy.notate;
- progtasks.name = progcopy.name;
- progtasks.sound = progcopy.sound;
-
- nexttest();
- }
-
- /*
- * dlgmisc() - do the "Misc Configuration" dialog.
- */
-
- dlgmisc()
- {
- DialogPtr dlg; /* our dialog */
- short itemhit; /* item # of the selected item */
- short curivbut; /* item # associated with iv playing */
- /* ...(== MI_*) */
- short curaccok; /* current value of "accidentals ok" */
- short itemtype;
- ControlHandle item;
- Rect itembox;
-
- /*
- * copy the state we're going to fiddle with
- * so we can leave the original unchanged, if necessary.
- */
-
- switch (any_seq) {
- case SEQ_HARM: curivbut = MI_HARM; break;
- case SEQ_MEL: curivbut = MI_MEL; break;
- case SEQ_MIX: curivbut = MI_MIX; break;
- }
- curaccok = acc_ok;
-
- /*
- * Create and maintain the dialog,
- * Always updating the items' state before allowing user input.
- */
-
- dlg = GetNewDialog(DLGMISC, (char *) 0, (long) -1);
-
- do {
- radioset(dlg, curivbut, MI_HARM, MI_MIX);
- GetDItem(dlg, MI_ACCOK, &itemtype, &item, &itembox);
- SetCtlVal(item, curaccok ? 1 : 0);
-
- ModalDialog((ProcPtr) 0, &itemhit);
- switch (itemhit) {
- case MI_HARM:
- case MI_MEL:
- case MI_MIX:
- curivbut = itemhit;
- break;
- case MI_ACCOK:
- curaccok = !curaccok;
- break;
- }
- } while (itemhit != OK && itemhit != Cancel);
- DisposDialog(dlg);
-
- if (itemhit == Cancel) return;
-
- /*
- * Put the specified changes into effect.
- */
-
- switch (curivbut) {
- case MI_HARM: any_seq = SEQ_HARM; break;
- case MI_MEL: any_seq = SEQ_MEL; break;
- case MI_MIX: any_seq = SEQ_MIX; break;
- }
- acc_ok = curaccok;
-
- nexttest();
- }
-
- /*
- * flagbutton() - set the given buttons according to the state of a flag
- */
-
- flagbutton(dlg, flag, trueitem, falseitem)
- DialogPtr dlg; /* the open dialog to effect */
- short flag; /* a boolean */
- short trueitem; /* item to set if flag is true */
- short falseitem; /* item to set if flag is false */
- {
- if (flag) {
- (void) radioswitch(dlg, trueitem, falseitem);
- } else {
- (void) radioswitch(dlg, falseitem, trueitem);
- }
- }
-